define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Connectagency, $stateParams) {

		//接收参数
		$scope.act_id = $stateParams.id;
		
		//获取抽奖类型
		$scope.draw_type = 1;//默认是自动抽奖
		$scope.init_data = function(draw_type) {
			Connectagency.connectagency($scope.act_id,draw_type, function(data) {
				$scope.order = data.order;
			});
		}
		$scope.init_data($scope.draw_type);
	
		$scope.getDrawType = function(value){//自动
			$scope.draw_type = value;//$scope.draw_type变量主要是判断样式用
			$scope.init_data($scope.draw_type);
		}
	
	//删除
	  $scope.delete_act = function(id) {
			var i = 0;
			var n = -1;
			for(var o in $scope.order){//查找对应的下标
				if($scope.order[o].order_id == id){
					n = i;
					break;
				}
				i++;
			}
			if(n != -1){
				$scope.order.splice(n,1);//删除数组中的元素
			}
		}
        
	}

	controller.$inject = ['$scope', 'Connectagency','$stateParams'];
	
	return app.registerController("connectagencyctrl",controller);
});